package com.minzheng.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.minzheng.blog.dao.VisitLogDao;
import com.minzheng.blog.dto.VisitLogDTO;
import com.minzheng.blog.entity.VisitLog;
import com.minzheng.blog.service.VisitLogService;
import com.minzheng.blog.util.BeanCopyUtils;
import com.minzheng.blog.util.PageUtils;
import com.minzheng.blog.vo.ConditionVO;
import com.minzheng.blog.vo.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 操作日志服务
 *
 * @author silencezheng
 * @date 2023/02/21
 */
@Service
public class VisitLogServiceImpl extends ServiceImpl<VisitLogDao, VisitLog> implements VisitLogService {

    @Override
    public PageResult<VisitLogDTO> listvisitLogs(ConditionVO conditionVO) {
        Page<VisitLog> page = new Page<>(PageUtils.getCurrent(), PageUtils.getSize());
        // 查询日志列表
        Page<VisitLog> VisitLogPage = this.page(page, new LambdaQueryWrapper<VisitLog>()
                .orderByDesc(VisitLog::getId));
        List<VisitLogDTO> VisitLogDTOList = BeanCopyUtils.copyList(VisitLogPage.getRecords(), VisitLogDTO.class);
        return new PageResult<>(VisitLogDTOList, (int) VisitLogPage.getTotal());
    }
}
